package com.zmx.patientend.view.activity;


import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.giftedcat.easylib.selector.MultiImageSelector;
import com.zmx.patientend.BaseActivity;
import com.zmx.patientend.R;
import com.zmx.patientend.adapter.NineGridAdapter;
import com.zmx.patientend.listener.OnAddPicturesListener;
import com.zmx.patientend.utils.AllUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Unbinder;
import de.hdodenhof.circleimageview.CircleImageView;

/**
*时间：2020/6/16 14:12
*功能：开药问诊
*/
public class PrescribingPhysicianActivity extends BaseActivity {

    private Button button1, button2, button3, button4, next;
    private EditText editText;
    RecyclerView rvImages;

    NineGridAdapter adapter;
    private int maxNum = 9;
    Unbinder unbinder;
    List<String> mSelect;
    List<String> select;//图片路径
    private static final int REQUEST_IMAGE = 2;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_prescribing_physician;
    }

    @Override
    protected void initViews() {
        setToolbar(R.id.tool_bar);
        button1 = findViewById(R.id.button1);
        button1.setOnClickListener(this);
        button2 = findViewById(R.id.button2);
        button2.setOnClickListener(this);
        button3 = findViewById(R.id.button3);
        button3.setOnClickListener(this);
        button4 = findViewById(R.id.button4);
        button4.setOnClickListener(this);
        next = findViewById(R.id.next);
        next.setOnClickListener(this);
        editText = findViewById(R.id.editText);
        mSelect = new ArrayList<>();
        rvImages = findViewById(R.id.rv_images);
        rvImages.setLayoutManager(new GridLayoutManager(this, 3));
        adapter = new NineGridAdapter(this, mSelect, rvImages);
        adapter.setMaxSize(maxNum);
        rvImages.setAdapter(adapter);
        adapter.setOnAddPicturesListener(new OnAddPicturesListener() {
            @Override
            public void onAdd() {
                pickImage();
            }
        });
//        getAllDoctor();
    }

    /**
     * 选择添加图片
     */
    private void pickImage() {

        MultiImageSelector selector = MultiImageSelector.create(mActivity);
        selector.showCamera(true);
        selector.count(maxNum);
        selector.multi();
        selector.origin(mSelect);
        selector.start(mActivity, REQUEST_IMAGE);

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode) {

            case 2:
                if (resultCode == RESULT_OK) {

                    select = data.getStringArrayListExtra(MultiImageSelector.EXTRA_RESULT);

                    mSelect.clear();
                    for (String s : select) {

                        if (s != "") {
                            Log.e("路径", "路径：" + s);
                            mSelect.add(s);
                        }
                    }

                    adapter.notifyDataSetChanged();
                }
                break;
        }

    }

    @Override
    protected void onDestroy() {

        super.onDestroy();

        if (unbinder != null) {
            unbinder.unbind();
        }

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);

        switch (v.getId()) {

            case R.id.button1:
                //判断是否已经有内容了
                if (editText.getText().toString().equals("")) {

                    editText.setText("症状描述：");

                } else {

                    editText.setText(editText.getText() + "\n" + "\n" + "症状描述：");

                }
                break;

            case R.id.button2:

                //判断是否已经有内容了
                if (editText.getText().toString().equals("")) {

                    editText.setText("患者时长：");

                } else {

                    editText.setText(editText.getText() + "\n" + "\n" + "患者时长：");

                }
                break;

            case R.id.button3:
                if (editText.getText().toString().equals("")) {

                    editText.setText("医院检查：");

                } else {

                    editText.setText(editText.getText() + "\n" + "\n" + "医院检查：");

                }
                break;
            case R.id.button4:
                if (editText.getText().toString().equals("")) {

                    editText.setText("用药情况：");

                } else {

                    editText.setText(editText.getText() + "\n" + "\n" + "用药情况：");

                }
                break;

            case R.id.next:

                //判断描述是否为空
                if (AllUtil.isNotNull(editText.getText().toString())) {

                    Toast("提交成功");
                    finish();


                } else {

                    Toast("请详细描述你的病情");

                }

                break;

            default:
                break;
        }

    }

}
